import 'package:flutter/cupertino.dart';
import 'package:flutter_app/bean/list_other_problem_entity.dart';
import 'package:flutter_app/network/Api.dart';
import 'package:flutter_app/network/ResultData.dart';
import 'package:flutter_app/ui/mine/film/film_detail/film_detail_view.dart';
import 'package:flutter_app/utils/toast_utils.dart';
import 'package:flutter_app/values/MyColors.dart';
import 'package:get/get.dart';
import 'film_list_state.dart';

class FilmListLogic extends GetxController {
  final FilmListState state = FilmListState();

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
    // listOtherProblem(state.currentPage.value, status);
  }

  /// 获取随手拍问题数据列表
  Future<void> listOtherProblem(int currentPage, String status) async {
    Map<String, dynamic> page = {
      "status": status,
    };
    Map<String, dynamic> param = {
      "currentPage": currentPage,
      'pageSize': 15,
      'param': page
    };
    ResultData resultData = await Api.listOtherProblem(param);
    if (resultData.isSuccess) {
      if (currentPage == 1) {
        state.listOtherProblemEntity = ListOtherProblemEntity.fromJson(resultData.data['data']);
      } else if (currentPage > 1) {
        state.listOtherProblemEntity!.content!.addAll(ListOtherProblemEntity.fromJson(resultData.data['data']).content!);
      }
      update();
    } else {
      toast.show(resultData.data["message"]);
    }
  }

  String getTagText(String flowStatus) {
    String str = "审核中";
    switch (flowStatus) {
      case "0":
      case "11":
      case "21":
        str = "审核中";
        break;
      case "12":
      case "22":
      case "32":
        str = "未采纳";
        break;
      case "31":
        str = "已采纳";
        break;
      default:
    }
    return str;
  }

  Color getTextColor(String flowStatus) {
    Color textColor = MyColors.FF2763B9;
    switch (flowStatus) {
      case "0":
      case "11":
      case "21":
        textColor = MyColors.FF2763B9;
        break;
      case "12":
      case "22":
      case "32":
        textColor = MyColors.FFF03F35;
        break;
      case "31":
        textColor = MyColors.FF2AAB33;
        break;
      default:
    }
    return textColor;
  }

  Color getBackgroundColor(String flowStatus) {
    Color backgroundColor = MyColors.FFECF6FE;
    switch (flowStatus) {
      case "0":
      case "11":
      case "21":
        backgroundColor = MyColors.FFECF6FE;
        break;
      case "12":
      case "22":
      case "32":
        backgroundColor = MyColors.FFFDE6E5;
        break;
      case "31":
        backgroundColor = MyColors.FFECFEEE;
        break;
      default:
    }
    return backgroundColor;
  }

  void goToFilmDetail(String? id) {
    Get.to(() => FilmDetailPage(title: "随手拍上报记录详情",), arguments: id);
  }

  @override
  void onClose() {
    super.onClose();
  }
}
